package sjg.DataStructures.search;

/**
 * 线性查找算法
 */
public class SeqSearch {
    public static void main(String[] args) {
        int arr[] = {1, 9, 11, -1, 34, 89};// 没有顺序的数组
        int index = seqSearch(arr, 89);
        if (index == -1) {
            System.out.println("没有匹配到值");
        } else {
            System.out.println("匹配到值，索引为: " + index);
        }
    }

    private static int seqSearch(int[] arr, int i) {
        for (int j = 0; j < arr.length; j++) {
            if (arr[j] == i) {
                return j;
            }
        }
        return -1;
    }
}
